﻿namespace IBTrader.Model
{
    using IBTrader.Frontend;
    using IBTrader.Modules.Market;
    using System;
    using System.Collections.ObjectModel;

    public class Contracts : ObservableCollection<Contract>
    {
    }
    public class Contract : NotifyPropertyChanged
    {
        public Contract() { }
        public Contract(Store store)
        {
            Created = DateTime.Now;
            Id = store.Contracts.Count + 1;
        }
        private bool _reqEnd { get; set; }
        private string _symbol, _currency, _securityType, _exchange, _expiry, _multiplier, _primaryExchange;
        private decimal _increment;

        public int Id { get; set; }
        public DateTime Created { get; set; }

        public string Symbol { get { return _symbol; } set { _symbol = value; Changed(() => Symbol); } }
        public string Exchange { get { return _exchange; } set { _exchange = value; Changed(() => Exchange); } }
        public string Currency { get { return _currency; } set { _currency = value; Changed(() => Currency); } }
//price
        public string Expiry { get { return _expiry; } set { _expiry = value; Changed(() => Expiry); } }
        public string SecurityType
        {
            get { return _securityType; }
            set
            {
                _securityType = value;
                Changed(() => SecurityType);
                if (value == "FUT" && !string.IsNullOrWhiteSpace(Symbol) && string.IsNullOrWhiteSpace(Expiry))
                    Expiry = Expirations.Expiration(Symbol, DateTime.UtcNow);
            }
        }
        public string Multiplier { get { return _multiplier; } set { _multiplier = value; Changed(() => Multiplier); } }
        public decimal MinTick { get { return _increment; } set { _increment = value; Changed(() => MinTick); } }
        public bool ReqEnd { get { return _reqEnd; } set { _reqEnd = value; Changed(() => ReqEnd); } }
        public string PrimaryExchange { get { return _primaryExchange; } set { _primaryExchange = value; Changed(() => PrimaryExchange); } }
        public override string ToString()
        {
            return string.Format("{0} {1} {2}", SecurityType, Symbol, Exchange);
        }
    }
}
